package com.ssy.lingxi.purchase.controller.tender;

import cn.hutool.core.bean.BeanUtil;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.purchase.api.dto.response.tender.InviteTenderInCheckRecordResponse;
import com.ssy.lingxi.purchase.entity.tender.InviteTenderInCheckRecord;
import com.ssy.lingxi.purchase.service.tender.IInviteTenderInCheckRecordService;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @menu: 招投标-招标内部状态流转管理
 * 内部状态流转记录管理类
 * @author jw.chen
 * @version 2.0.0
 * @date 2021/3/1
 */
@RestController
@RequestMapping("/purchase/inviteTenderInCheckRecord")
public class InviteTenderInCheckRecordController extends BaseController {

    @Resource
    private IInviteTenderInCheckRecordService inviteTenderInCheckRecordService;

    /**
     * 查询内部审核记录
     * @param inviteTenderId 招标id
     */
    @RequestMapping(value = "/getInviteTenderInCheckRecord", method = RequestMethod.GET)
    public Wrapper<List<InviteTenderInCheckRecordResponse>> getInviteTenderInCheckRecord(@RequestParam("inviteTenderId") Long inviteTenderId) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        List<InviteTenderInCheckRecord> inviteTenderInCheckRecordList = inviteTenderInCheckRecordService.getInviteTenderInCheckRecord(sysUser, inviteTenderId);
        List<InviteTenderInCheckRecordResponse> inviteTenderInCheckRecordResponseList = inviteTenderInCheckRecordList.stream().map(inviteTenderInCheckRecord -> BeanUtil.copyProperties(inviteTenderInCheckRecord, InviteTenderInCheckRecordResponse.class)).collect(Collectors.toList());
        return Wrapper.success(inviteTenderInCheckRecordResponseList);
    }

    /**
     * 查询内部审核记录--操作日志
     * @param inviteTenderId 招标id
     */
    @RequestMapping(value = "/getInviteTenderInCheckRecordList", method = RequestMethod.GET)
    public Wrapper<PageData<InviteTenderInCheckRecordResponse>> getInviteTenderInCheckRecordList(PageVO pageVO, @RequestParam(value = "inviteTenderId", required = false) Long inviteTenderId, @RequestParam(value = "startTime", required = false) Long startTime, @RequestParam(value = "endTime", required = false) Long endTime) {
        Page<InviteTenderInCheckRecord> result = inviteTenderInCheckRecordService.getInviteTenderInCheckRecordList(pageVO, inviteTenderId, startTime, endTime);
        List<InviteTenderInCheckRecordResponse> inviteTenderInCheckRecordResponseList = result.getContent().stream().map(inviteTenderInCheckRecord -> BeanUtil.copyProperties(inviteTenderInCheckRecord, InviteTenderInCheckRecordResponse.class)).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), inviteTenderInCheckRecordResponseList));
    }
}
